package gang.org.springframework.framework.core;

import gang.org.springframework.framework.util.GangClassUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;

/**
 * @author gang.chen
 * @description
 * @Date 2021/12/15 13:34
 */
public abstract class GangKotlinDetector {

    private static final boolean kotlinReflectPresent;
    private static final Class<? extends Annotation> kotlinMetadata;

    static{
        Class<?> metadata;
        ClassLoader classLoader = GangKotlinDetector.class.getClassLoader();
        try {
            metadata = GangClassUtils.forName("kotlin.Metadata", classLoader);
        }catch (Exception e){
            metadata = null;
        }
        kotlinMetadata = (Class<? extends Annotation>) metadata;
        kotlinReflectPresent = GangClassUtils.isPresent("kotlin.reflect.full.KClasses",classLoader);
    }

    public static boolean isKotlinReflectPresent() {
        return kotlinReflectPresent;
    }

    public static boolean isKotlinType(Class<?> clazz){
        return (kotlinMetadata != null && clazz.getDeclaredAnnotation(kotlinMetadata) != null);
    }

    //TODO
    public static Type getGenericReturnType(Method method){
        return null;
    }



}
